"""
@Author    : ghenyar
@Time      : 2025/8/28 13:01
@File      : configs_model.py
@Desc      : 配置管理
"""
from datetime import datetime
from sqlalchemy import BigInteger, String, Text, Boolean, DateTime
from sqlalchemy.orm import Mapped, mapped_column
from sqlalchemy.sql import func

from ..models import DatabaseModel, table_prefix


class ConfigsModel(DatabaseModel):
    __tablename__ = f"{table_prefix}configs"
    __table_args__ = {"comment": "系统配置表"}

    id: Mapped[int] = mapped_column(BigInteger, primary_key=True, autoincrement=True, comment="配置ID")
    types: Mapped[str] = mapped_column(String(100), nullable=False, comment="配置类型")
    key: Mapped[str] = mapped_column(String(100), nullable=False, comment="配置键")
    value: Mapped[str | None] = mapped_column(Text, nullable=True, comment="配置参数(Json)")
    enable: Mapped[bool] = mapped_column(Boolean, default=True, nullable=False, comment="状态  True:启用  False:停用")


class ImgGroupsModel(DatabaseModel):
    __tablename__ = f"{table_prefix}img_groups"
    __table_args__ = {"comment": "图片分组表"}

    id: Mapped[int] = mapped_column(BigInteger, primary_key=True, autoincrement=True, comment="分组ID")
    name: Mapped[str] = mapped_column(String(255), nullable=False, comment="分组名称")

    created_at: Mapped[datetime] = mapped_column(DateTime, nullable=False, server_default=func.now(),
                                                 comment="创建时间")
    updated_at: Mapped[datetime | None] = mapped_column(DateTime, nullable=True, onupdate=func.now(),
                                                        comment="更新时间")


class ImgsModel(DatabaseModel):
    __tablename__ = f"{table_prefix}imgs"
    __table_args__ = {"comment": "图片管理表"}

    id: Mapped[int] = mapped_column(BigInteger, primary_key=True, autoincrement=True, comment="图片ID")
    name: Mapped[str] = mapped_column(String(255), nullable=False, comment="图片原始名称")
    group_id: Mapped[int] = mapped_column(BigInteger, nullable=True, default=0, comment="分组ID")
    src: Mapped[str] = mapped_column(String(255), nullable=False, comment="图片地址")
    created_at: Mapped[datetime] = mapped_column(DateTime, nullable=False, server_default=func.now(),
                                                 comment="创建时间")
    updated_at: Mapped[datetime | None] = mapped_column(DateTime, nullable=True, onupdate=func.now(),
                                                        comment="更新时间")
